﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public partial class DataContext
    {
        public List<SanPham> GetListSanPham()
        {
            return db.SanPhams.ToList();
        }
        public SanPham GetSanPhamById(Guid id)
        {
            return db.SanPhams.Where(c => c.MaSP == id).FirstOrDefault();
        }
        public void DeleteSanPham(SanPham cthd)
        {
            db.Entry(cthd).State = EntityState.Deleted;
            db.SaveChanges();
        }
        public void InsertSanPham(SanPham cthd)
        {
            cthd.MaSP = Guid.NewGuid();
            db.Entry(cthd).State = EntityState.Added;
            db.SaveChanges();
        }
        public void UpdateSanPham(SanPham cthd)
        {
            db.Entry(cthd).State = EntityState.Modified;
            db.SaveChanges();
        }
    }
}
